import {
    Message
} from 'element-ui'
// arr：原数组；str：匹配字段；val：当前节点字段
const getContractParent = (arr, str, val) => {
    for (let i = 0; i < arr.length; i++) {
        const item = arr[i]
        if (item[str] === val) {
            return []
        } else {
            if (item.children) {
                let res = []
                if ((res = getContractParent(item.children, str, val)) !== false) {
                    res.push(item)
                    return res
                }
            }
        }
    }
    return false
}

// 复制到剪切板
const copy = (con, msg) => {
    const el = document.createElement('input')
    el.setAttribute('value', con)
    document.body.appendChild(el)
    el.select()
    document.execCommand('copy')
    document.body.removeChild(el)
    Message.success(msg || '复制成功')
}

export { getContractParent, copy }
